/*
	Copyright (c) 2009 Mark Walters
	
	Permission is hereby granted, free of charge, to any person obtaining a copy
	of this software and associated documentation files (the "Software"), to deal
	in the Software without restriction, including without limitation the rights
	to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
	copies of the Software, and to permit persons to whom the Software is
	furnished to do so, subject to the following conditions:
	
	The above copyright notice and this permission notice shall be included in
	all copies or substantial portions of the Software.
	
	THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
	IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
	FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
	AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
	LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
	OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
	THE SOFTWARE.
*/

package smlab.utils
{
	import flash.utils.Dictionary;
	
	/**
	 * 
	 * 根据SVG1.0定义颜色名和16进制的值。
	 * The ColorName class defines the names and hexadecimal values of the colors defined in SVG 1.0.
	 * The colors include the X11 colors supported by popular browsers with the addition of gray/grey variants from SVG 1.0.
	 * The resulting list is precisely the same as the SVG 1.0 color keyword names.
	 * The SVG 1.0 colors include the HTML4 colors, based on the VGA colors.
	 * @see http://www.w3.org/TR/css3-color/#html4
	 * @see http://www.w3.org/TR/css3-color/#svg-color
	 * 
	 * @author Mark Walters
	 */
	public class ColorName_SM
	{
		//HTML4 COLOR KEYWORDS - VGA
		//@see http://www.w3.org/TR/css3-color/#html4
		public static const AQUA:ColorName_SM = new ColorName_SM( "aqua", 0x00FFFF );
		public static const BLACK:ColorName_SM = new ColorName_SM( "black", 0x000000 );
		public static const BLUE:ColorName_SM = new ColorName_SM( "blue", 0x0000FF );
		public static const FUCHSIA:ColorName_SM = new ColorName_SM( "fuchsia", 0xFF00FF );
		public static const GRAY:ColorName_SM = new ColorName_SM( "gray", 0x808080 );
		public static const GREEN:ColorName_SM = new ColorName_SM( "green", 0x008000 );
		public static const LIME:ColorName_SM = new ColorName_SM( "lime", 0x00FF00 );
		public static const MAROON:ColorName_SM = new ColorName_SM( "maroon", 0x800000 );
		public static const NAVY:ColorName_SM = new ColorName_SM( "navy", 0x000080 );
		public static const OLIVE:ColorName_SM = new ColorName_SM( "olive", 0x808000 );
		public static const PURPLE:ColorName_SM = new ColorName_SM( "purple", 0x800080 );
		public static const RED:ColorName_SM = new ColorName_SM( "red", 0xFF0000 );
		public static const SILVER:ColorName_SM = new ColorName_SM( "silver", 0xC0C0C0 );
		public static const TEAL:ColorName_SM = new ColorName_SM( "teal", 0x008080 );
		public static const WHITE:ColorName_SM = new ColorName_SM( "white", 0xFFFFFF );
		public static const YELLOW:ColorName_SM = new ColorName_SM( "yellow", 0xFFFF00 );
		
		//SVG COLOR KEYWORDS - X11 ( INCLUDES THE 16 HTML4 - VGA COLORS )
		//@see http://www.w3.org/TR/css3-color/#svg-color
		public static const ALICE_BLUE:ColorName_SM = new ColorName_SM( "aliceBlue", 0xF0F8FF );
		public static const ANTIQUE_WHITE:ColorName_SM = new ColorName_SM( "antiqueWhite", 0xFAEBD7 );
		public static const AQUAMARINE:ColorName_SM = new ColorName_SM( "aquamarine", 0x7FFFD4 );
		public static const AZURE:ColorName_SM = new ColorName_SM( "azure", 0xF0FFFF );
		public static const BEIGE:ColorName_SM = new ColorName_SM( "beige", 0xF5F5DC );
		public static const BISQUE:ColorName_SM = new ColorName_SM( "bisque", 0xFFE4C4 );
		public static const BLANCHED_ALMOND:ColorName_SM = new ColorName_SM( "blanchedAlmond", 0xFFEBCD );
		public static const BLUE_VIOLET:ColorName_SM = new ColorName_SM( "blueViolet", 0x8A2BE2 );
		public static const BROWN:ColorName_SM = new ColorName_SM( "brown", 0xA52A2A );
		public static const BURLY_WOOD:ColorName_SM = new ColorName_SM( "burlyWood", 0xDEB887 );
		public static const CADET_BLUE:ColorName_SM = new ColorName_SM( "cadetBlue", 0x5F9EA0 );
		public static const CHARTREUSE:ColorName_SM = new ColorName_SM( "chartreuse", 0x7FFF00 );
		public static const CHOCOLATE:ColorName_SM = new ColorName_SM( "chocolate", 0xD2691E );
		public static const CORAL:ColorName_SM = new ColorName_SM( "coral", 0xFF7F50 );
		public static const CORNFLOWER_BLUE:ColorName_SM = new ColorName_SM( "cornflowerBlue", 0x6495ED );
		public static const CORNSILK:ColorName_SM = new ColorName_SM( "cornsilk", 0xFFF8DC );
		public static const CRIMSON:ColorName_SM = new ColorName_SM( "crimson", 0xDC143C );
		public static const CYAN:ColorName_SM = new ColorName_SM( "cyan", 0x00FFFF );
		public static const DARK_BLUE:ColorName_SM = new ColorName_SM( "darkBlue", 0x00008B );
		public static const DARK_CYAN:ColorName_SM = new ColorName_SM( "darkCyan", 0x008B8B );
		public static const DARK_GOLDEN_ROD:ColorName_SM = new ColorName_SM( "darkGoldenRod", 0xB8860B );
		public static const DARK_GRAY:ColorName_SM = new ColorName_SM( "darkGray", 0xA9A9A9 );
		public static const DARK_GREY:ColorName_SM = new ColorName_SM( "darkGrey", 0xA9A9A9 );
		public static const DARK_GREEN:ColorName_SM = new ColorName_SM( "darkGreen", 0x006400 );
		public static const DARK_KHAKI:ColorName_SM = new ColorName_SM( "darkKhaki", 0xBDB76B );
		public static const DARK_MAGENTA:ColorName_SM = new ColorName_SM( "darkMagenta", 0x8B008B );
		public static const DARK_OLIVE_GREEN:ColorName_SM = new ColorName_SM( "darkOliveGreen", 0x556B2F );
		public static const DARK_ORANGE:ColorName_SM = new ColorName_SM( "darkOrange", 0xFF8C00 );
		public static const DARK_ORCHID:ColorName_SM = new ColorName_SM( "darkOrchid", 0x9932CC );
		public static const DARK_RED:ColorName_SM = new ColorName_SM( "darkRed", 0x8B0000 );
		public static const DARK_SALMON:ColorName_SM = new ColorName_SM( "darkSalmon", 0xE9967A );
		public static const DARK_SEA_GREEN:ColorName_SM = new ColorName_SM( "darkSeaGreen", 0x8FBC8F );
		public static const DARK_SLATE_BLUE:ColorName_SM = new ColorName_SM( "darkSlateBlue", 0x483D8B );
		public static const DARK_SLATE_GRAY:ColorName_SM = new ColorName_SM( "darkSlateGray", 0x2F4F4F );
		public static const DARK_SLATE_GREY:ColorName_SM = new ColorName_SM( "darkSlateGrey", 0x2F4F4F );
		public static const DARK_TURQUOISE:ColorName_SM = new ColorName_SM( "darkTurquoise", 0x00CED1 );
		public static const DARK_VIOLET:ColorName_SM = new ColorName_SM( "darkViolet", 0x9400D3 );
		public static const DEEP_PINK:ColorName_SM = new ColorName_SM( "deepPink", 0xFF1493 );
		public static const DEEP_SKY_BLUE:ColorName_SM = new ColorName_SM( "deepSkyBlue", 0x00BFFF );
		public static const DIM_GRAY:ColorName_SM = new ColorName_SM( "dimGray", 0x696969 );
		public static const DIM_GREY:ColorName_SM = new ColorName_SM( "dimGrey", 0x696969 );
		public static const DODGER_BLUE:ColorName_SM = new ColorName_SM( "dodgerBlue", 0x1E90FF );
		public static const FIRE_BRICK:ColorName_SM = new ColorName_SM( "fireBrick", 0xB22222 );
		public static const FLORAL_WHITE:ColorName_SM = new ColorName_SM( "floralWhite", 0xFFFAF0 );
		public static const FOREST_GREEN:ColorName_SM = new ColorName_SM( "forestGreen", 0x228B22 );
		public static const GAINSBORO:ColorName_SM = new ColorName_SM( "gainsboro", 0xDCDCDC );
		public static const GHOST_WHITE:ColorName_SM = new ColorName_SM( "ghostWhite", 0xF8F8FF );
		public static const GOLD:ColorName_SM = new ColorName_SM( "gold", 0xFFD700 );
		public static const GOLDEN_ROD:ColorName_SM = new ColorName_SM( "goldenRod", 0xDAA520 );
		public static const GREY:ColorName_SM = new ColorName_SM( "grey", 0x808080 );
		public static const GREEN_YELLOW:ColorName_SM = new ColorName_SM( "greenYellow", 0xADFF2F );
		public static const HONEY_DEW:ColorName_SM = new ColorName_SM( "honeyDew", 0xF0FFF0 );
		public static const HOT_PINK:ColorName_SM = new ColorName_SM( "hotPink", 0xFF69B4 );
		public static const INDIAN_RED:ColorName_SM = new ColorName_SM( "indianRed", 0xCD5C5C );
		public static const INDIGO:ColorName_SM = new ColorName_SM( "indigo", 0x4B0082 );
		public static const IVORY:ColorName_SM = new ColorName_SM( "ivory", 0xFFFFF0 );
		public static const KHAKI:ColorName_SM = new ColorName_SM( "khaki", 0xF0E68C );
		public static const LAVENDER:ColorName_SM = new ColorName_SM( "lavender", 0xE6E6FA );
		public static const LAVENDER_BLUSH:ColorName_SM = new ColorName_SM( "lavenderBlush", 0xFFF0F5 );
		public static const LAWN_GREEN:ColorName_SM = new ColorName_SM( "lawnGreen", 0x7CFC00 );
		public static const LEMON_CHIFFON:ColorName_SM = new ColorName_SM( "lemonChiffon", 0xFFFACD );
		public static const LIGHT_BLUE:ColorName_SM = new ColorName_SM( "lightBlue", 0xADD8E6 );
		public static const LIGHT_CORAL:ColorName_SM = new ColorName_SM( "lightCoral", 0xF08080 );
		public static const LIGHT_CYAN:ColorName_SM = new ColorName_SM( "lightCyan", 0xE0FFFF );
		public static const LIGHT_GOLDEN_ROD_YELLOW:ColorName_SM = new ColorName_SM( "lightGoldenRodYellow", 0xFAFAD2 );
		public static const LIGHT_GRAY:ColorName_SM = new ColorName_SM( "lightGray", 0xD3D3D3 );
		public static const LIGHT_GREY:ColorName_SM = new ColorName_SM( "lightGrey", 0xD3D3D3 );
		public static const LIGHT_GREEN:ColorName_SM = new ColorName_SM( "lightGreen", 0x90EE90 );
		public static const LIGHT_PINK:ColorName_SM = new ColorName_SM( "lightPink", 0xFFB6C1 );
		public static const LIGHT_SALMON:ColorName_SM = new ColorName_SM( "lightSalmon", 0xFFA07A );
		public static const LIGHT_SEA_GREEN:ColorName_SM = new ColorName_SM( "lightSeaGreen", 0x20B2AA );
		public static const LIGHT_SKY_BLUE:ColorName_SM = new ColorName_SM( "lightSkyBlue", 0x87CEFA );
		public static const LIGHT_SLATE_GRAY:ColorName_SM = new ColorName_SM( "lightSlateGray", 0x778899 );
		public static const LIGHT_SLATE_GREY:ColorName_SM = new ColorName_SM( "lightSlateGrey", 0x778899 );
		public static const LIGHT_STEEL_BLUE:ColorName_SM = new ColorName_SM( "lightSteelBlue", 0xB0C4DE );
		public static const LIGHT_YELLOW:ColorName_SM = new ColorName_SM( "lightYellow", 0xFFFFE0 );
		public static const LIME_GREEN:ColorName_SM = new ColorName_SM( "limeGreen", 0x32CD32 );
		public static const LINEN:ColorName_SM = new ColorName_SM( "linen", 0xFAF0E6 );
		public static const MAGENTA:ColorName_SM = new ColorName_SM( "magenta", 0xFF00FF );
		public static const MEDIUM_AQUA_MARINE:ColorName_SM = new ColorName_SM( "mediumAquaMarine", 0x66CDAA );
		public static const MEDIUM_BLUE:ColorName_SM = new ColorName_SM( "mediumBlue", 0x0000CD );
		public static const MEDIUM_ORCHID:ColorName_SM = new ColorName_SM( "mediumOrchid", 0xBA55D3 );
		public static const MEDIUM_PURPLE:ColorName_SM = new ColorName_SM( "mediumPurple", 0x9370D8 );
		public static const MEDIUM_SEA_GREEN:ColorName_SM = new ColorName_SM( "mediumSeaGreen", 0x3CB371 );
		public static const MEDIUM_SLATE_BLUE:ColorName_SM = new ColorName_SM( "mediumSlateBlue", 0x7B68EE );
		public static const MEDIUM_SPRING_GREEN:ColorName_SM = new ColorName_SM( "mediumSpringGreen", 0x00FA9A );
		public static const MEDIUM_TURQUOISE:ColorName_SM = new ColorName_SM( "mediumTurquoise", 0x48D1CC );
		public static const MEDIUM_VIOLET_RED:ColorName_SM = new ColorName_SM( "mediumVioletRed", 0xC71585 );
		public static const MIDNIGHT_BLUE:ColorName_SM = new ColorName_SM( "midnightBlue", 0x191970 );
		public static const MINT_CREAM:ColorName_SM = new ColorName_SM( "mintCream", 0xF5FFFA );
		public static const MISTY_ROSE:ColorName_SM = new ColorName_SM( "mistyRose", 0xFFE4E1 );
		public static const MOCCASIN:ColorName_SM = new ColorName_SM( "moccasin", 0xFFE4B5 );
		public static const NAVAJO_WHITE:ColorName_SM = new ColorName_SM( "navajoWhite", 0xFFDEAD );
		public static const OLD_LACE:ColorName_SM = new ColorName_SM( "oldLace", 0xFDF5E6 );
		public static const OLIVE_DRAB:ColorName_SM = new ColorName_SM( "oliveDrab", 0x6B8E23 );
		public static const ORANGE:ColorName_SM = new ColorName_SM( "orange", 0xFFA500 );
		public static const ORANGE_RED:ColorName_SM = new ColorName_SM( "orangeRed", 0xFF4500 );
		public static const ORCHID:ColorName_SM = new ColorName_SM( "orchid", 0xDA70D6 );
		public static const PALE_GOLDEN_ROD:ColorName_SM = new ColorName_SM( "paleGoldenRod", 0xEEE8AA );
		public static const PALE_GREEN:ColorName_SM = new ColorName_SM( "paleGreen", 0x98FB98 );
		public static const PALE_TURQUOISE:ColorName_SM = new ColorName_SM( "paleTurquoise", 0xAFEEEE );
		public static const PALE_VIOLET_RED:ColorName_SM = new ColorName_SM( "paleVioletRed", 0xD87093 );
		public static const PAPAYA_WHIP:ColorName_SM = new ColorName_SM( "papayaWhip", 0xFFEFD5 );
		public static const PEACH_PUFF:ColorName_SM = new ColorName_SM( "peachPuff", 0xFFDAB9 );
		public static const PERU:ColorName_SM = new ColorName_SM( "peru", 0xCD853F );
		public static const PINK:ColorName_SM = new ColorName_SM( "pink", 0xFFC0CB );
		public static const PLUM:ColorName_SM = new ColorName_SM( "plum", 0xDDA0DD );
		public static const POWDER_BLUE:ColorName_SM = new ColorName_SM( "powderBlue", 0xB0E0E6 );
		public static const ROSY_BROWN:ColorName_SM = new ColorName_SM( "rosyBrown", 0xBC8F8F );
		public static const ROYAL_BLUE:ColorName_SM = new ColorName_SM( "royalBlue", 0x4169E1 );
		public static const SADDLE_BROWN:ColorName_SM = new ColorName_SM( "saddleBrown", 0x8B4513 );
		public static const SALMON:ColorName_SM = new ColorName_SM( "salmon", 0xFA8072 );
		public static const SANDY_BROWN:ColorName_SM = new ColorName_SM( "sandyBrown", 0xF4A460 );
		public static const SEA_GREEN:ColorName_SM = new ColorName_SM( "seaGreen", 0x2E8B57 );
		public static const SEA_SHELL:ColorName_SM = new ColorName_SM( "seaShell", 0xFFF5EE );
		public static const SIENNA:ColorName_SM = new ColorName_SM( "sienna", 0xA0522D );
		public static const SKY_BLUE:ColorName_SM = new ColorName_SM( "skyBlue", 0x87CEEB );
		public static const SLATE_BLUE:ColorName_SM = new ColorName_SM( "slateBlue", 0x6A5ACD );
		public static const SLATE_GRAY:ColorName_SM = new ColorName_SM( "slateGray", 0x708090 );
		public static const SLATE_GREY:ColorName_SM = new ColorName_SM( "slateGrey", 0x708090 );
		public static const SNOW:ColorName_SM = new ColorName_SM( "snow", 0xFFFAFA );
		public static const SPRING_GREEN:ColorName_SM = new ColorName_SM( "springGreen", 0x00FF7F );
		public static const STEEL_BLUE:ColorName_SM = new ColorName_SM( "steelBlue", 0x4682B4 );
		public static const TAN:ColorName_SM = new ColorName_SM( "tan", 0xD2B48C );
		public static const THISTLE:ColorName_SM = new ColorName_SM( "thistle", 0xD8BFD8 );
		public static const TOMATO:ColorName_SM = new ColorName_SM( "tomato", 0xFF6347 );
		public static const TURQUOISE:ColorName_SM = new ColorName_SM( "turquoise", 0x40E0D0 );
		public static const VIOLET:ColorName_SM = new ColorName_SM( "violet", 0xEE82EE );
		public static const WHEAT:ColorName_SM = new ColorName_SM( "wheat", 0xF5DEB3 );
		public static const WHITE_SMOKE:ColorName_SM = new ColorName_SM( "whiteSmoke", 0xF5F5F5 );
		public static const YELLOW_GREEN:ColorName_SM = new ColorName_SM( "yellowGreen", 0x9ACD32 );
		
		/**
		 * @private
		 */
		protected static var nameDict:Dictionary;
		
		/**
		 * @private
		 */
		protected static var colorDict:Dictionary;
		
		/**
		 * @private
		 */
		private var _name:String;
		
		/**
		 * @private
		 */
		private var _color:uint;
		
		/**
		 * Constructor.
		 * 
		 * @param name The string name of a color (case-insensitive).
		 * @param color The hexadecimal value of a color.
		 */
		public function ColorName_SM( name:String, color:uint )
		{
			if( !nameDict ) nameDict = new Dictionary();
			if( !colorDict ) colorDict = new Dictionary();
			
			this.name = name;
			this.color = color;
		}
		
		/**
		 * The string name of a color (case-insensitive).
		 */
		public function get name():String
		{
			return _name;
		}
		
		/**
		 * @private
		 */
		public function set name( value:String ):void
		{
			_name = value;
			nameDict[ value.toLowerCase() ] = this;
		}
		
		/**
		 * The hexadecimal value of a color.
		 */
		public function get color():uint
		{
			return _color;
		}
		
		/**
		 * @private
		 */
		public function set color( value:uint ):void
		{
			_color = value;
			colorDict[ value ] = this;
		}
		
		/**
		 * Returns the corresponding ColorName object from the string name.
		 * 
		 * @param name The string name of a color (case-insensitive).
		 * @return A ColorName object.
		 */
		public static function getColorNameByName( name:String ):ColorName_SM
		{
			return nameDict[ name.toLowerCase() ];
		}
		
		/**
		 * Returns the corresponding ColorName object from the hexadecimal value.
		 * 
		 * @param color The hexadecimal value of a color.
		 * @return A ColorName object.
		 */
		public static function getColorNameByColor( color:uint ):ColorName_SM
		{
			return colorDict[ color ];
		}
		
		/**
		 * Returns a string containing all the properties of the ColorName object.
		 */
		public function toString():String
		{
			var colorString:String = color.toString( 16 ).toUpperCase();
			while( 6 > colorString.length ) colorString = "0" + colorString;
			return "[ColorName name=\"" + name + "\" color=0x" + colorString + "]";
		}
		
	}
}